/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.subThread;

import cn.ac.iie.di.tools.JettyClient;
import java.util.concurrent.BlockingQueue;
import org.apache.log4j.Logger;

/**
 *
 * @author zhangyun
 */
public class Agent implements Runnable {
    
    public String xml;
    public String agentIP;
    public String jsonFiles;//需要下发给agent的json文件
    public String subjobid;
    public String hdfsPathForRDD;
    public BlockingQueue<String> rs_xml;
    private static Logger logger = Logger.getLogger(Agent.class);
    
    public Agent(String agentIP, String xml, String subjobid, String hdfsPathForRDD, BlockingQueue<String> rs_xml, String jsonFiles) {
        this.xml = xml;
        this.agentIP = agentIP;
        this.subjobid = subjobid;
        this.hdfsPathForRDD = hdfsPathForRDD;
        this.rs_xml = rs_xml;
        this.jsonFiles = jsonFiles;
    }
    
    @Override
    public void run() {
        //用jetty发送xml，等待回复
        String rs = "";
        logger.info("the jsonfiles is: " + jsonFiles);
        rs = new JettyClient().send(agentIP, xml, subjobid, hdfsPathForRDD, jsonFiles);
        if (rs != null && !rs.equals("")) {
            logger.info(subjobid + " " + agentIP + " rs is not empty!");
            rs_xml.add(rs);
        } else {
            logger.info(subjobid + " " + agentIP + " rs is empty!");
        }
    }
    
}
